import java.nio.channels.SocketChannel;
import java.text.DateFormat;

/**
 * This class is used to keep track of server information
 *  I am a server as well, but what are the information tht 
 *  I need to know about other servers
 */

public class Server {
	private String ServerName; // alice, bob, charlie, delta
	private String ip; // ip address of the server
	private int serverPort; // the port in which 
	private SocketChannel channel; // the TCP connection between me and this server
	private boolean connectionEstablished = false; 
	private long last_heart_beat_time; // last time I heard a heart beat from this server
	
	private boolean connectionAttempted = false; 
	
	public Server(String name, String ip, int port){
		this.ServerName = name;
		this.ip = ip;
		this.serverPort = port;
		channel = null;
		last_heart_beat_time = 0;
		connectionEstablished = false;
	}
	
	public boolean hasNoChannel(){
		if(channel==null){
			return true;
		}else{
			return false;
		}
	}
	
	public boolean isChannelEstablished(){
		if(channel==null){
			return false;
		}else{
			if(connectionEstablished)
				return true;
			else
				return false;
		}
	}

	public void setConnectionEstablished(boolean connectionEstablished) {
		this.connectionEstablished = connectionEstablished;
	}

	public SocketChannel getChannel() {
		return channel;
	}

	public void setChannel(SocketChannel channel) {
		this.channel = channel;
	}
	
	public String getIp() {
		return ip;
	}
	
	public int getPort() {
		return serverPort;
	}

	public boolean connectionAttempted() {
		return connectionAttempted;
	}

	public void setConnectionAttempted(boolean connectionAttempted) {
		this.connectionAttempted = connectionAttempted;
	}
	
	public long getLast_heart_beat_time() {
		return last_heart_beat_time;
	}

	public void setLast_heart_beat_time(long t) {
		this.last_heart_beat_time = t;
	}

	public String getServerName() {
		return ServerName;
	}
	
	public String toString(){
		return ServerName + "	ip=" + ip + "	port=" + Integer.toString(serverPort);
	}
}
